/*---------------------------------------------------------------------------
//
//	Copyright(C) SMIT Corporation, 2000-2010.
//
//  File	:	physical.h
//	Purpose	:	Header File for DVB-CI Physical layer
//	History :
//    Version    Date	  	    Written by	     Notes
//	  1.0	     31/07/1997     SCM              Initial implementation
//
---------------------------------------------------------------------------*/
#ifndef __PHYSICAL_H
#define __PHYSICAL_H

#include "sm_types.h"
#include "xmsg.h"

#ifdef __cplusplus
extern "C" {
#endif


/****************************************************************************
*
* Symbol/Structures Definitions
*
****************************************************************************/

// states of link state diagram
#define PHY_NOT_USED	1
#define PHY_IDLE 		2
#define PHY_CONNECTED 	3
#define GETPHYSTATENAME(cmd)		((cmd)==PHY_NOT_USED?"PHY_NOT_USED":((cmd)==PHY_IDLE?"PHY_IDLE":((cmd)==PHY_CONNECTED?"PHY_CONNECTED":"UNKN_PHYSTAT")))

#define PHPOLL_TIMEOUT		  20 //1000 // (10*1000) //org is 10 /* polling on PHYSICAL Driver period in ms		*/

typedef struct
{
	unsigned short m_slotId;			// reference to physical link
	unsigned char  m_state;				// state of transport connection
}physlot_t;      						// informations for one module

//#define PIPE_PHY "/tmp/phyfifo"
#define PIPE_PHY "phyfifo_host.log"
extern int g_pipePhy;

/****************************************************************************
*
* Function Prototypes
*
****************************************************************************/

int  physical(void* param);				/* Entry point of PHYSICAL Task						*/
int  physical_read(void* param);

BOOL  PHYSICAL_Init(void);			/* Initialization Module							*/
void PHYSICAL_State(xmsg_t* pXmsg);	        /* Entry point of the Physical State Diagram Module */
void PHYSICAL_End(void);			/* Ending module 									*/

int  PHYSICAL_Insert(xmsg_t* pXmsg);			/* Module Insertion received from PHYSICAL driver	*/
int  PHYSICAL_Data(xmsg_t* pXmsg);			/* Module Data received from PHYSICAL driver		*/
int  PHYSICAL_Error(xmsg_t* pXmsg);			/* Module Error received from PHYSICAL driver		*/
int  PHYSICAL_Extract(xmsg_t* pXmsg);		/* Module Extraction  received from PHYSICAL driver */
int  PHYSICAL_Lpdu(xmsg_t* pXmsg);			/* LPDU received from LINK Task						*/

int  PHYSICAL_GetIndex(unsigned short slotId);					/* take a new entry in g_phy_tab_slot		*/
int  PHYSICAL_GetSlot(unsigned short slotId);					/* get the current entry in g_phy_tab_slot */
int  PHYSICAL_FreeIndex(int index, unsigned short slotId);		/* free an g_phy_tab_slot entry			*/


/****************************************************************************
*
* State Diagram
*
****************************************************************************/

int PHYSICAL_Action(int index, xmsg_t* pXmsg);		/* Entry Point		*/
int PHYSICAL_Idle(int index, xmsg_t* pXmsg);			/* idle state		*/
int PHYSICAL_Connected(int index, xmsg_t* pXmsg);	/* connetcted state	*/

//************************************
// Method:    Interrogate whether CAM is present in the corresponding slot
// FullName:  PHYSICAL_CurrentStatus
// Access:    private 
// Returns:   int
// Qualifier:
// Parameter: void
//************************************
int PHYSICAL_CurrentStatus(int index);

typedef enum
{
	PHY_STATUS_OK,
	PHY_STATUS_FAILED,
}PHY_STATUS_T;

typedef int (*pfPHYSICALEventCallback)(PHY_STATUS_T);

int PHYSICAL_RegistorErrorCallback(pfPHYSICALEventCallback cb);

#ifdef __cplusplus
}
#endif

#endif	// __PHYSICAL_H

